﻿@using hc.epm.UI.Common;
@using hc.epm.DataModel.Basic;
@using hc.Plat.Common.Extend;
@using hc.epm.Common;
@model IEnumerable<Base_Company>
@{
    ViewBag.Title = "单位管理";
}
<div class="content-right date-wrap fl c">
    <div class="top-url">
        <span><a href="/home/welcome" target="mainFrame">首页</a> </span> > <span> <a href="">组织机构</a> </span>
    </div>
    <div class="search mt5">
        <form class="layui-form" action="" method="get">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">名称 : </label>
                    <div class="layui-input-inline"><input type="text" name="name" id="name" placeholder="请输入单位名称" autocomplete="off" class="layui-input" value="@ViewBag.name" /></div> 
                    <label class="layui-form-label">类型 : </label>
                    <div class="layui-input-inline">
                        
                        @Html.DropDownList("type", null, new { @class = "form-control" })
                    </div> 
                </div>
                <input type="submit" class="layui-btn layui-btn-radius layui-btn-warm" lay-filter="search" value="搜 索" />

                

            </div>
        </form>
    </div>
    <div class="main mt5">
        <div class="btns">
            <a href="javascript:;" target="mainFrame" data-module="@AdminModule.AdminOrganization" data-right="add" id="add" class="checkright">新 增</a>
            <a href="javascript:;" target="mainFrame" data-module="@AdminModule.AdminOrganization" data-right="delete" class="checkright" id="delete">删 除</a>
        </div>
        <div class="layui-form">
            <table class="layui-table">
                <thead>
                    <tr>
                        <th width="5%" class="table-center">
                            <input type="checkbox" lay-skin="primary" lay-filter="allChoose" />
                            <div class="layui-unselect layui-form-checkbox" lay-skin="primary"><i class="layui-icon"></i></div>
                        </th>
                        <th width="12%" class="table-left">Code编码</th>
                        <th class="table-left">单位名称</th>
                        <th width="12%" class="table-left">单位电话</th>
                        <th width="12%" class="table-left">类型</th>
                        <th width="12%" class="table-left">单位ID</th>
                        <th width="15%" class="table-center">组织机构</th>
                        <th width="8%" class="table-center">操作</th>
                    </tr>
                </thead>
                <tbody>
                    @if (Model != null && Model.Count() > 0)
                    {
                        foreach (var item in Model)
                        {
                            <tr>

                                @if (item.Type == "Admin")
                                {
                                    <td class="table-center">
                                        <input type="checkbox" lay-skin="primary" disabled="disabled" />
                                        <input type="hidden" name="id-@item.Id" id="id-@item.Id" value="@item.Id" />
                                    </td>
                                }
                                else
                                {
                                    <td class="table-center">
                                        <input type="checkbox" lay-skin="primary" name="chName" />
                                        <input type="hidden" name="id-@item.Id" id="id-@item.Id" value="@item.Id" />
                                    </td>
                                }


                                <td class="table-left">@item.Code</td>
                                <td class="table-left">@item.Name</td>
                                <td class="table-left">@item.Phone</td>
                                <td class="table-left">  @item.Type  </td>
                                <td class="table-left">@item.Id</td>
                                <td class="table-center">
                                    <a href="/Organization/branch?leftPId=@item.SId&rightPId=@item.SId" class="organization-link text-link" target="mainFrame" data-itemid="@item.SId" title="组织机构">组织机构</a>&nbsp;&nbsp;
                                </td>
                                <td class="table-center">
                                    @if (item.Type != "Admin")
                                    {
                                        <a href="/Organization/edit?id=@item.SId" target="mainFrame" class="editor-link checkright" data-itemid="@item.SId" title="编辑" data-module="@AdminModule.AdminOrganization" data-right="modify"><i class='glyphicon glyphicon-pencil handle-blue'></i></a>
                                    }
                                    <a href="/Organization/detail?id=@item.SId" class="detail-link checkright" data-itemid="@item.SId" title="详情" data-module="@AdminModule.AdminOrganization" data-right="info"><i class='glyphicon glyphicon-list-alt handle-blue'></i></a>
                                </td>
                            </tr>
                        }
                    }
                    else
                    {
                        <tr>
                            <td colspan="12" class="table-center">
                                暂无数据
                            </td>

                        </tr>
                    }
                </tbody>
            </table>
        </div>
        <div id="page"></div>

    </div>
</div>
<script type="text/javascript">
    //若无数据隐藏分页组件
    if ('@ViewBag.Total' == 0) {
        $("#page").hide();
    }
    layui.use(['layer', 'form', 'element', 'laypage'], function () {
        var layer = layui.layer, form = layui.form, element = layui.element, $ = layui.jquery, laypage = layui.laypage;
        laypage.render({
            elem: 'page',
            count: @ViewBag.Total,
            curr:@ViewBag.pageIndex,
            layout: ['prev', 'page', 'next', 'skip','count', ],
            jump:function(obj,first){
                if (!first){
                    //得到了当前页，用于向服务端请求对应数据
                    var curr = obj.curr;
                    var search = $("form").serialize();
                    window.location.href = "/Organization/Index?pageIndex=" + curr +"&" + search;
                }
            }
        });
        //表格全选
        layui.use('form', function () {
            var $ = layui.jquery, form = layui.form;
            //全选
            form.on('checkbox(allChoose)', function (data) {
                var child = $(data.elem).parents('table').find('tbody input[name="chName"]');
                child.each(function (index, item) {
                    item.checked = data.elem.checked;
                });
                form.render('checkbox');
            });
        });
        //新增单位
        $("#add").on("click",function(){
            window.location.href = "/Organization/Add?rightPId=0";
        })
        //删除
        $("#delete").click(function () {
            var chkItems = $('.layui-table tbody input[type="checkbox"]:checked');
            var ids = "";
            chkItems.each(function (index, item) {//获取选择要删除的项
                var hfId = $(this).parent().find("input[type='hidden']");
                ids += hfId.val() + ",";
            });
            if (ids != "") {
                parent.layer.confirm("确认要删除所选择的项？", { icon: 3 }, function () {//批量删除单位
                    $.post("/Organization/Delete", { ids: ids }, function (data) {
                        if (data.Flag) {
                            parent.layer.msg("删除成功", { time: 1000, icon: 1 });
                            var search = $("form").serialize();
                            window.location.href = "/Organization/Index?pageIndex=1&" + search;
                        } else {
                            parent.layer.alert(data.Message, { icon: 2 });
                        }
                    }, "json");
                }, function () {
                    return;
                })

            } else {
                parent.layer.alert("请先选择要删除的数据", { icon: 2 });
            }
         
        });
    });
</script>